<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>问题药品信息管理</title>
    <!--引入本地的css和js-->
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/admin/style.css}" media="all">
    <script type="text/html" id="indexTpl">
        {{d.LAY_TABLE_INDEX+1}}
    </script>
    <!-- 引入layui css -->
    <!--<link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui-v2.5.6/css/layui.css" />-->
    <!-- 引入layui js -->
    <!--<script src="https://www.layuicdn.com/layui-v2.5.6/layui.js"></script>-->
</head>
<body class="layui-layout-body">
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">问题药品信息列表</div>
                <div class="layui-card-body">
                    <table class="layui-hide" id="main-table" lay-filter="main-table"></table>
                    <script type="text/html" id="toolbarDemo">
                        <span class="layui-inline" style="width: 240px">
                            <input class="layui-input" name="param" id="param" placeholder="根据药品名称查询" autocomplete="off">
                        </span>
                        <span class="layui-btn layui-btn-sm layui-bg-red" lay-event="querySearch">
                            <i class="layui-icon layui-icon-search"></i>查询
                        </span>
                        <span class="layui-btn layui-btn-sm layui-bg-green" lay-event="add">
                            <i class="layui-icon layui-icon-add-1"></i>添加
                        </span>
                    </script>
                    <script type="text/html" id="barDemo">
                        <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="return">退货</a>
                        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script th:src="@{/static/layui/layui.js}"></script>
<script>
    layui.use(['table', 'form'], function () {
        var $ = layui.$;
        var table = layui.table;
        table.render({
            elem: '#main-table',
            height: 650,
            url: '/drugProblemInfo/drugProblemInfoQueryPage',
            method: 'POST',
            page: true,
            id: 'table-load',
            toolbar: '#toolbarDemo',
            cols: [
                [
                    {title: '序号', templet: '#indexTpl', width: 60, align: 'center'},
                    {field: 'dname', title: '药品名称', align: 'center'},
                    {field: 'druginnum', title: '药品批号', align: 'center'},
                    {field: 'dcount', title: '问题药品数量', align: 'center'},
                    {field: 'reason', title: '出问题的原因', align: 'center'},
                    {
                        field: 'create_time',
                        title: '操作的时间',
                        width: 250,
                        align: 'center',
                        templet: "<div>{{layui.util.toDateString(d.createTime,'yyyy-MM-dd HH:mm:ss')}}</div>"
                    },
                    {field: 'isreturn', title: '状态', align: 'center'},
                    {title: '操作', width: 180, align: 'center', toolbar: '#barDemo', field: 'right'}
                ]
            ]
        });

        //监听头工具栏的事件
        table.on('toolbar(main-table)', function (obj) {
            switch (obj.event) {
                case 'add':
                    layer.open({
                        type: 2,
                        title: '新增问题药品信息信息',
                        content: '/drugProblemInfo/drugProblemInfoPage',
                        shade: [0.8, '#393d49'],
                        area: ['600px', '500px'],
                        btn: ['确定', '取消'],
                        yes: function (index, layero) {
                            var iframeWindow = window['layui-layer-iframe' + index];
                            var submit = layero.find('iframe').contents().find("#LAY-from-submit")
                            //监听提交
                            iframeWindow.layui.form.on('submit(LAY-from-submit)', function (data) {
                                var filed = data.field;
                                $.ajax({
                                    url: '/drugProblemInfo/drugProblemInfoAdd',
                                    data: filed,
                                    async: false,
                                    cache: false,
                                    success: function (str) {
                                        if (str.code === 0) {
                                            table.reload('table-load');
                                        }
                                        layer.msg(str.msg, {icon: str.icon, anim: str.anim});
                                    }
                                });
                                layer.close(index);//关闭弹窗
                            });
                            submit.trigger('click');
                        },
                        success: function (layero, index) {

                        }

                    });
                    break;
                case 'querySearch':
                    var param = $('#param').val();
                    table.reload('table-load', {
                        where: {
                            param: param
                        }
                    });
                    $('#param').val(param);
                    break;
            }
        });

        //监听编辑和删除
        table.on('tool(main-table)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'edit':
                    layer.open({
                        type: 2,
                        title: '编辑问题药品信息',
                        content: '/drugProblemInfo/drugProblemInfoQueryById?id=' + data.id,
                        shade: [0.8, '#393d49'],
                        area: ['600px', '500px'],
                        btn: ['确定', '取消'],
                        yes: function (index, layero) {
                            var iframeWindow = window['layui-layer-iframe' + index];
                            var submit = layero.find('iframe').contents().find("#LAY-from-submit")
                            //监听提交
                            iframeWindow.layui.form.on('submit(LAY-from-submit)', function (data) {
                                var filed = data.field;
                                $.ajax({
                                    url: '/drugProblemInfo/drugProblemInfoEdit',
                                    data: filed,
                                    async: false,
                                    cache: false,
                                    success: function (str) {
                                        if (str.code === 0) {
                                            table.reload('table-load');
                                        }
                                        layer.msg(str.msg, {icon: str.icon, anim: str.anim});
                                    }
                                });
                                layer.close(index);//关闭弹窗
                            });
                            submit.trigger('click');
                        },
                        success: function (layero, index) {
                        }
                    });
                    break;
                case 'return':
                    layer.confirm('确认要退货问题药品吗？', function (index) {
                        $.ajax({
                            url: '/drugProblemInfo/drugProblemInfoReturn?id=' + data.id,
                            data: null,
                            async: false,
                            cache: false,
                            success: function (str) {
                                table.reload('table-load');
                                layer.msg(str.msg, {icon: str.icon, anim: str.anim});
                            }
                        });
                    });
                    break;

                case 'del':
                    layer.confirm('确认要删除本条问题药品记录吗？', function (index) {
                        $.ajax({
                            url: '/drugProblemInfo/drugProblemInfoDelById?id=' + data.id,
                            data: null,
                            async: false,
                            cache: false,
                            success: function (str) {
                                table.reload('table-load');
                                layer.msg(str.msg, {icon: str.icon, anim: str.anim});
                            }
                        });
                    });
                    break;
            }
        });
    });
</script>

</html>